import time
import unittest

from configparser import ConfigParser
from Pages.PlanePage import PlanePage
from Pages.hotelPage import HotelPage
from Pages.tripPage import tripPage
from Pages.AdminPage import AdminPage
from Pages.adminHotelDetailPage import adminHotelDetailPage
from Pages.OrderListPage import OrderListPage
from Pages.OBTHotelDetailPage import OBTHotelDetailPage
from Public import Gl
from Public.Login import Login
from Public.BaseOperate import BaseOperate

class hotel(unittest.TestCase):
    def setUp(self):
        parse = ConfigParser()
        #win需使用配置文件绝对路径
        parse.read('E:\DTSL\DTSL\Public\configurations.ini')
        self.driver = Gl.BrowserEngine(self).open_browser(self)
        self.L = Login()
        self.urlOBT = parse.get('OBT','url')
        self.useridOBT = parse.get('OBT','userid')
        self.passwordOBT = parse.get('OBT','password')
        self.urlAdmin = parse.get('admin','url')
        self.useridAdmin = parse.get('admin','userid')
        self.passwordAdmin = parse.get('admin','password')
        self.hotelName = "DTG苏州测试专用酒店"
        self.BO = BaseOperate()

    def test_0hotelOrder(self):
        PP = PlanePage()
        HT = HotelPage()
        #登录
        self.L.LoginOBT(self.urlOBT,  self.useridOBT, self.passwordOBT)
        #提示判断点击关闭
      #  PP.closeNotice()
      #  PP.click_Close()
        HT.click_hotelIcon()
        HT.chooseCity()
        HT.chooseDate()
        HT.input_HotelName(self.hotelName)
        #   国内酒店是第2个搜索按钮
        PP.click_searchBtn(1)
        PP.closeNotice()
      #  HT.click_noPrece()
        HT.click_checkDetail()
      #到店付房型政策  HT.click_faceToFace()
      #  HT.click_lvxingjingli()
        # 提交订单操作
        HT.choosePolicy()
        HT.click_submit()
        time.sleep(10)

        TP = tripPage()
        global hotelOrderNo
        hotelOrderNo = TP.checkHotelAndSubmint(self.hotelName)
        print(hotelOrderNo)
    

    def test_1hotelOrderOperate(self):
        AP = AdminPage()
        self.L.LoginAdmin(self.urlAdmin, self.useridAdmin, self.passwordAdmin)
        AP.goToHotelOrder()
        AP.selectOrder(hotelOrderNo)
        hotelDetailPage = adminHotelDetailPage()
        hotelDetailPage.acceptBook()
        

    def test_2hotelOrderChange(self):
        PP = PlanePage()
        HT = HotelPage()
        #登录
        self.L.LoginOBT(self.urlOBT,  self.useridOBT, self.passwordOBT)
        PP.goOrderList()
        OL = OrderListPage()
        OL.selectOrder(hotelOrderNo)
        hotelDetailPage = OBTHotelDetailPage()
        hotelDetailPage.applyChange()
    #    hotelDetailPage.getOrderNo()

    '''登录管家后台处理酒店订单'''
    def test_3hotelOrderOperate(self):
        AP = AdminPage()
        self.L.LoginAdmin(self.urlAdmin, self.useridAdmin, self.passwordAdmin)
        AP.goToHotelOrder()
        AP.selectOrder(hotelOrderNo)
        hotelDetailPage = adminHotelDetailPage()
        hotelDetailPage.acceptChange()
        
        
    def test_4hotelOrderRefund(self):
        PP = PlanePage()
        HT = HotelPage()
        #登录
        self.L.LoginOBT(self.urlOBT,  self.useridOBT, self.passwordOBT)
        time.sleep(1)
        self.BO.closeNotice()
        time.sleep(1)
        PP.goOrderList()
        OL = OrderListPage()
        OL.selectOrder(hotelOrderNo)
        hotelDetailPage = OBTHotelDetailPage()
        hotelDetailPage.applyRefund()
        hotelOrderStatus = hotelDetailPage.getOrderStatus()
        print(hotelOrderStatus)


    '''登录管家后台处理酒店订单'''
    def test_5hotelOrderOperate(self):
        AP = AdminPage()
        self.L.LoginAdmin(self.urlAdmin, self.useridAdmin, self.passwordAdmin)
        AP.goToHotelOrder()
        AP.selectOrder(hotelOrderNo)
        hotelDetailPage = adminHotelDetailPage()
        hotelDetailPage.acceptRefund()



    def tearDown(self):
        self.driver.quit()


if __name__ == '__main__':
    unittest.main()
